package com.hex.ds.hdtp.core.app.common.util;

import lombok.extern.slf4j.Slf4j;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

@Slf4j
public class StreamGobbler extends Thread{

    InputStream is;

    String type;

    StringBuffer sb = new StringBuffer();

    public StreamGobbler(InputStream is, String type) {
        this.is = is;
        this.type = type;
    }

    public String getContent() {
        return this.sb.toString();
    }

    public void run() {
        try {
            InputStreamReader read = new InputStreamReader(this.is, "UTF-8");
            BufferedReader bufferReader = new BufferedReader(read);
            String line;
            while ((line = bufferReader.readLine()) != null)
                this.sb.append(line).append(System.getProperty("line.separator"));
        } catch (Exception e) {
            log.error("", e.getStackTrace());
        }
    }
}
